<!DOCTYPE html>
<html>
<head>
	<title>店铺角色管理</title>
	<include file='public/head'>
	<style>
		.layui-legend-size{font-size:14px !important;}
		.layui-nopadding{padding:0 !important;}
		.layui-overflow{overflow:auto;}
		.layui-nomargin{margin: 0 !important;}
		.layui-bottom{border-bottom:1px solid rgb(226, 226, 226);}
		.layui-input{height:30px !important; }
		.layui-form-search-item .layui-inline{margin-bottom: 5px;} 
		.layui-form-search-item label{margin-left: 15px;}
		.layui-table-page {padding: 7px 0px 0px;}
		.layui-field-padding{border-width: 1px;padding:0 0 5px 10px;}
	</style>		
</head>
<body>
<!-- layui-tab开始 -->
<div class="layui-tab " lay-filter="demo-tab">
	<!-- 顶部导航菜单开始 -->
	<div class="layui-tab-nav" >
        <ul class="layui-tab-title">
			{:getNav('store','store_rbac/index')};
		</ul>
	</div>
	<!-- 顶部导航菜单结束 -->
	<fieldset class="layui-elem-field layui-field-title layui-field-padding">
		<legend class="layui-legend-size">店铺角色</legend>
		<!-- 内容开始-->
    	<div id="store_rbac" class="store-rbac-tree"></div>
    	<!-- 内容结束-->
	</fieldset>
	

</div>
<include file='public/scripts' />
<script type="text/javascript">
;(function(){
    var tree = layui.tree;
    
    let rbacData = {$rbacData|default='[]'};
    
    tree.render({
        elem: '#store_rbac'
        ,data: rbacData
        ,onlyIconControl:true
    });
    
    //添加角色
    $(document).on( 'click' , '.btn-add' , function(){
        let url = '{:cmf_plugin_url("Store://store_rbac/addRolePost")}';
        let id = getId( this );
        layer.prompt({
            title:'添加角色'
        },function(value, index, elem){
            comPost( url , {parent_id:id,name:value} , function(res){
                window.location.reload();
            });
        });
    } );
    $(document).on( 'click' , '.btn-edit' , function(){
        let url = '{:cmf_plugin_url("Store://store_rbac/editRolePost")}';
        let id = getId( this );
        let old = $(this).data('name');
        layer.prompt({
            title:'修改角色',
            value:old
        },function(value, index, elem){
            comPost( url , {id:id,name:value} , function(res){
                window.location.reload();
            });
        });
    } );
    
    $(document).on( 'click' , '.btn-del' , function(){
        let id = getId( this );
        layer.confirm( '确定要删除此角色吗?' , { icon : 3 , title:'删除角色提示'} , function(){
            comPost( '{:cmf_plugin_url("Store://store_rbac/delRole")}' , { id:id } , function(){
                window.location.reload();
            });
        } );
    } );
    
    $(document).on( 'click' , '.btn-rbac' , function(){
        let id = getId( this );
        layer.open({
            type: 2,
            title: '角色授权',
            shade: [0],
            area: ['800px', '700px'],
            btn:[ '保存','取消'],
            maxnin:true,
            anim: 2,
            content: '{:cmf_plugin_url("Store://store_rbac/setRbac")}?role_id='+id, 
            yes:function( index , layero ){
              var res = window[layero.find('iframe')[0]['name']].callback( index );  
            },
            end: function(){ 
                
            }
        });
    } );
    
    $(document).on( 'click' , '.btn-user' , function(){
        let id = getId( this );
        layer.open({
            type: 2,
            title: '用户列表',
            shade: [0],
            area: ['800px', '700px'],
            btn:[ '关闭'],
            maxnin:true,
            anim: 2,
            content: '{:cmf_plugin_url("Store://store_rbac/showUser")}?id='+id
        });
    } );
    
    //获取id
    function getId( _this ){
        return $(_this).data( 'tag' );
    }
    //提交
    function comPost( url , data , success , error ){
        $.post( url , data, function( res ){
            layer.msg( res.message , { icon:(res.code==200?1:5) , time:500 } , function(){
                if( res.code == 200 ){
                    success && success( res );
                }else{
                    error && error( res );
                }
            } );
        } );
    }
    
})()
</script>
</body>
</html>